<!DOCTYPE html>
<html>

    <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">


        <title>玩家充值</title>
        <meta name="keywords" content="">
        <meta name="description" content="">

        <link rel="shortcut icon" href="favicon.ico"> <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
        <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
        <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
        <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">

    </head>

    <body class="gray-bg">
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-sm-8">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>玩家充值</h5>
                        </div>
                        <div class="ibox-content">
                            <form class="form-horizontal m-t" id="commentForm" >
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">玩家ID：</label>
                                    <div class="col-sm-3">
                                        <input id="openid" name="openid" minlength="2" type="text" class="form-control" required="" aria-required="true">
                                    </div>
                                    <span class="cred t1"></span>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">充值数量：</label>
                                    <div class="col-sm-3">
                                        <input id="num" name="num" minlength="2" type="text" class="form-control" required="" aria-required="true">
                                    </div>
                                    <span class="cred t2"></span>
                                </div class="form-group">
                                <eq name='gm_admin.role' value='1'>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-4 cgray">
                                        可用余额：<span id="remain">{$remain}</span>
                                    </div>
                                </div>
                                </eq>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-4">
                                        <button class="btn btn-primary" type="button">立即充值</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

            </div>

        </div>


        <!-- 全局js -->
        <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
        <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>

        <!-- 自定义js -->
        <script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>

        <!-- jQuery Validation plugin javascript-->
        <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>
        <script src="__PUBLIC__/admin/js/plugins/validate/messages_zh.min.js"></script>
        <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
        <!-- <script src="__PUBLIC__/admin/js/demo/form-validate-demo.js"></script> -->

        <script type="text/javascript">
            $(".btn-primary").click(function() {
            if ($.trim($("#openid").val()) == '') {
            $('.t1').html('请输入玩家ID！');
            return false;
            } else{
            $('.t1').html('');
            }
            if ($.trim($("#num").val()) == '') {
            $('.t2').html('请输入充值数量！');
            return false;
            } else{
            $('.t2').html('');
            }
            if ({$gm_admin.role} == 1) {
            if ($.trim($("#num").val()) > {$remain}) {
            $('.t2').html('余额不足！');
            return false;
            } else{
            $('.t2').html('');
            }
            }
            var params = $("input").serialize();
            var url = "{:U('Admin/Admin/paySave')}";
            $.ajax({
            type: "post",
                    url: url,
                    dataType: "json",
                    data: params,
                    success: function (data) {
                    if (data == 'nexist') {
                    $('.t1').html('该玩家ID不存在！');
                    } else if (data['status'] == 'success') {
                        
                    layer.msg('为游戏ID为 ' + data['openid'] + ' 玩家 ' + data['nickname'] + ' 充值房卡 ' + data['num'] + ' 张成功！', {
                    icon: 1, time: 10000, btn: [ '确定']}, function(){
                    window.location.href = "{:U('Admin/Admin/pay')}";
                    });
                    // alert('充值成功！'); 
                    // window.location.href = "{:U('Admin/Admin/pay')}";
                    } else {
                    alert('充值失败！');
                    }
                    }
            });
            });
        </script>


    </body>

</html>
